package commons;

import java.util.ArrayList;
import java.util.List;

import org.codeandmagic.android.gauge.demo.R;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;

public class DatePickerFragment extends DialogFragment implements
		OnDateSetListener {

	private String dateCheck = "";
	private int day, month, year;
	private boolean check = false;

	DatePickerFragment(String check) {
		dateCheck = check;
	}

	public DatePickerFragment(String check, int day, int month, int year) {
		dateCheck = check;
		this.day = day;
		this.month = month;
		this.year = year;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current date as the default date in the picker
		// Create a new instance of DatePickerDialog and return it
		if (check = false)
			return null;
		else
			return new DatePickerDialog(getActivity(), this, year, month - 1,
					day);
	}



	public void onDateSet(DatePicker view, int year, int month, int day) {
		// Do something with the date chosen by the user
		check = true;
		EditText fromDate = (EditText) getActivity().findViewById(
				R.id.edtFromDate);
		EditText toDate = (EditText) getActivity().findViewById(R.id.edtToDate);

		if ("fromdate".equals(dateCheck)) {
			fromDate.setText(day + "/" + (month + 1) + "/" + year);
			fromDate.setError(null);
		}
		if ("todate".equals(dateCheck)) {
			toDate.setText((day + 1) + "/" + (month + 1) + "/" + year);
			toDate.setError(null);
		}
		returnDate(day, month, year);
	}

	public List<Integer> returnDate(int year, int month, int day) {
		List<Integer> listDate = new ArrayList<Integer>();
		listDate.add(day);
		listDate.add(month);
		listDate.add(year);
		return listDate;
	}
}
